﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */
#ifndef USBPORT_H
#define USBPORT_H

#include <QObject>
#include <windows.h>
#include <QTimer>
#include <QQueue>

struct SendFramStruct {
    int total = 0;
    uint16_t sendBufferLen = 0;
    uint8_t *sendBuffer = nullptr;
};

namespace UsbPortClass {
class UsbPort : public QObject {
    Q_OBJECT
public:
    explicit UsbPort(QObject *parent = nullptr);
    ~UsbPort() override;
    bool OpenDevice(const CHAR *path, BOOL openRw);
    void CloseDevice();
    void UsbThread(uint8_t *buffer, uint16_t bufferLen);
    bool IsOpen() const;
    void SetMs(int sleepms);

signals:
    void SignalReadData(uint8_t *buffer, uint32_t bufferLen);
public slots:
    void ReadThread();
    void SlotSendTimerOut();
protected:
    void SendData();
private:
    HANDLE deviceHandle;
    QTimer *sendTimer;
    QQueue<SendFramStruct> sendFramInfoque;
    int offsetCount = 0;
    int ms = 5;
};
}

#endif // USBPORT_H
